var openalllinks = {
  onMenuItemCommand: function(e) {
    var msgPane = document.getElementById("messagepane");

    if ( msgPane )
    {
        var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
        var branch = prefs.getBranch("extensions.openalllinks.");

        var exclude = false;
        var confirmationRequired = true;
        var confirmed;
        var excludeprefvalue;

        if ( branch.getPrefType("exclude") == prefs.PREF_STRING ) {
            excludeprefvalue = branch.getCharPref("exclude");

            if ( excludeprefvalue != "" ) {
                exclude = new RegExp( excludeprefvalue, "gi" );
            }
        }

        if ( branch.getPrefType("confirm") == prefs.PREF_BOOL ) {
            confirmationRequired = branch.getBoolPref("confirm");
        }

        var anchors = msgPane.contentDocument.getElementsByTagName("a");
        var href;

        var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
        var strBundle = document.getElementById("openalllinksbundle");

        var confirmDialogTitle = strBundle.getString("openString");
        var confirmDialogMessage = strBundle.getString("confirmString");


        for ( var i = 0; i < anchors.length; i++ )
        {
            href = anchors[i].href;
            if ( href.substring(0,7) == 'http://' || href.substring(0,8) == 'https://' ) {
                if ( exclude ) {
                    exclude.lastIndex = 0;
                    if ( exclude.test( href ) ) {
                        continue;
                    }
                }

                if ( confirmationRequired ) {
                    confirmed = promptService.confirm(window,confirmDialogTitle,confirmDialogMessage + "\r\n" + href );
                } else {
                    confirmed = true;
                }

                if ( confirmed ) {
                    messenger.launchExternalURL( href );
                }
            }
        }
    }
  }
};